package com.gm.commonlib.views.dialog;

import android.content.Context;
import android.text.InputFilter;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.gm.commonlib.R;
import com.gm.commonlib.filters.InputFilterEmoji;


public class InputDialogView extends LinearLayout {
    private Context context;
    private TextView titleTv;
    private EditText inputEd;
    private TextView closeBtn;
    private TextView subMitBtn;

    private TextView leftTv;
    private TextView rightTv;

    public InputDialogView(Context context) {
        super(context);
        this.context = context;
        initView();
    }

    public InputDialogView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        initView();
    }

    private void initView() {
        View contentView = LayoutInflater.from(context).inflate(R.layout.view_input_dialog, this);
        titleTv = contentView.findViewById(R.id.tv_notify_title);
        inputEd = contentView.findViewById(R.id.et_comment);
        closeBtn = contentView.findViewById(R.id.btn_close);
        subMitBtn = contentView.findViewById(R.id.btn_commit);
        leftTv=contentView.findViewById(R.id.leftTv);
        rightTv=contentView.findViewById(R.id.rightTv);
    }

    public void showTextView(String left,String right){
        leftTv.setText(left);
        rightTv.setText(right);
        leftTv.setVisibility(VISIBLE);
        rightTv.setVisibility(VISIBLE);
    }

    public void setTitleTv(String text) {
        titleTv.setText(text);
    }

    public void setInputEdHint(String text) {
        inputEd.setHint(text);
    }

    public void setCloseBtnListener(OnClickListener listener) {
        closeBtn.setOnClickListener(listener);
    }

    public void setsubMitBtnListener(OnClickListener listener) {
        subMitBtn.setOnClickListener(listener);
    }

    public String getInputText() {
        return inputEd.getText().toString();
    }

    public void setEdInputFillter(InputFilter[] inputFillter) {
        if (inputFillter == null) {
            inputEd.setFilters(new InputFilter[]{new InputFilterEmoji()});
        } else {
            inputEd.setFilters(inputFillter);
        }

    }
}
